package ace.tool.generate.code.impl.resolver.scheme.resolver.sdk;

import ace.tool.generate.code.impl.resolver.scheme.model.bo.sdk.ConstantClassInfo;
import ace.tool.generate.code.impl.resolver.scheme.model.dto.ClassFileInfo;
import ace.tool.generate.code.impl.resolver.scheme.model.dto.CommonInfo;
import ace.tool.generate.code.impl.resolver.scheme.model.dto.ProjectInfo;
import ace.tool.generate.code.impl.resolver.scheme.resolver.ClassFileInfoResolver;
import ace.tool.generate.code.impl.service.model.input.GenerateInput;
import java.util.HashMap;
import java.util.Map;
import lombok.Builder;
import lombok.RequiredArgsConstructor;
import org.apache.commons.text.StringSubstitutor;

/**
 * @author caspar
 * @date 2023/11/17 10:34
 */
@Builder
@RequiredArgsConstructor
public class ConstantClassInfoResolver {

  private final GenerateInput input;
  private final CommonInfo commonInfo;
  private final ProjectInfo sdkProjectInfo;

  public ConstantClassInfo resolve() {

    ClassFileInfo classFileInfo =
        ClassFileInfoResolver.builder()
            .className(input.getSdkConstantName())
            .classNameSuffix(input.getSdkConstantNameSuffix())
            .classPackagePrefix(input.getSdkConstantPackagePrefix())
            .rootPackageFullName(commonInfo.getRootPackageFullName())
            .sourceCodeRootDir(sdkProjectInfo.getSourceCodeRootDir())
            .build()
            .resolve();

    return ConstantClassInfo.builder().info(classFileInfo)
        .feignServiceName(this.getFeignServiceName())
        .build();
  }

  private String getFeignServiceName() {
    Map<String, String> data = new HashMap<>();
    data.put("projectName", this.input.getProjectName());
    return StringSubstitutor.replace("${projectName}-service", data);
  }
}
